package contreller

import (
	"SkillTextJD2/model"
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/jinzhu/gorm"
)

func BuyPageHandler(c *gin.Context) {
	// 从gin上下文拿数据库连接（根据你实际代码改）
	db := c.MustGet("db").(*gorm.DB)

	var flights []model.FlightInfo
	if err := db.Find(&flights).Error; err != nil {
		c.String(http.StatusInternalServerError, "查询机票数据失败: "+err.Error())
		return
	}

	// 渲染模板buy.html，传入 flights 列表，变量名叫 ccd
	c.HTML(http.StatusOK, "buy.html", gin.H{
		"ccd": flights,
	})
}
